package interfaz;

import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

import net.sf.jasperreports.engine.JRExporter;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.export.JRPdfExporter;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.JasperViewer;

import org.hibernate.Session;

import dao.utils.HibernateUtil;

/**
 * Clase que genera las facturas de la empresa
 * 
 * @author Hungry Lion
 *
 */
public class Factura{

	private static final long serialVersionUID = 1L;
	
	  
	public void generarFactura() throws Exception{
		
		JasperPrint jasperPrint;
		
		Session sesion=HibernateUtil.getSession();
	
		@SuppressWarnings("deprecation")
		JasperReport reporte;
		
		reporte = (JasperReport) JRLoader.loadObject("reporte3.jasper");	
		jasperPrint = JasperFillManager.fillReport(reporte, null, sesion.connection());
		
    
		JRExporter exporter = new JRPdfExporter();
    
		exporter.setParameter(JRExporterParameter.JASPER_PRINT,jasperPrint); 
		exporter.setParameter(JRExporterParameter.OUTPUT_FILE,new java.io.File("reportePDF.pdf"));
		exporter.exportReport();
    
		JasperViewer.viewReport(jasperPrint, false);      		
	    
		HibernateUtil.closeSession();
		
	 }	

}





